package newcoder_exp.justPractise;
import java.util.*;

import org.junit.*;

public class NC113 {
    public class Solution {
        /**
         * 验证IP地址:使用正则表达式
         * 返回IPv4/6
        **/
        public String solve (String IP) {
            if (isIpv4(IP)) {
                return "IPv4";
            } else if (isIpv6(IP)) {
                return "IPv6";
            } else {
                return "Neither";
            }
        }

        public boolean isIpv4(String s) {
            String regex = "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}";
            if (!s.matches(regex))  return false;
            String[] strs = s.split("\\.");
            int cur;
            for (String str: strs) {
                cur = Integer.parseInt(str);
                if (cur < 0 || cur > 255 || str.charAt(0) == '0' && str.length() > 0) {
                    return false;
                }
            }

            return true;
        }   

        public boolean isIpv6(String s) {
            String regex = "(\\w{1,4}:){7}\\w{1,4}";
            if (!s.matches(regex)) return false;
            else return true;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        int[] nums = new int[]{};
       String res =  s.solve("256.256.256.256");
       System.out.println(res);
    }
}